<?php

namespace common\observer;

use support\SingletonTrait;
use Webman\Stomp\Client;
use teamones\dbeventObserver\interfaces\SplObserver;
use teamones\dbeventObserver\interfaces\SplSubject;

/**
 * 任务完成或者开始 同步到实体状态
 */
class TaskStatusSyncToEntity implements SplObserver
{
    use SingletonTrait;

    /**
     * @inheritDoc
     */
    public function update(SplSubject $subject): void
    {
        $updateData = $subject->getSplUpdateData();
        if (!isset($updateData['task_status'])) {
            return;
        }
        $task = $subject->getSubjectData();

        if (empty($task['source_entity_id'])) {
            return;
        }
        Client::send('check_entity_status', build_queue_data_with_xu(['entity_id' => $task['source_entity_id']]));

    }

}
